utils.js ➔ describe(ꞌutilsꞌ)   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 123

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
c 2
b 1
f 0
nc 1
nop 0
dl 0
loc 123
rs 8.2857

4 Functions

Rating   Name   Duplication   Size   Complexity  
A utils.js ➔ ... ➔ describe(ꞌmergeꞌ) 0 59 1
A utils.js ➔ ... ➔ it(ꞌremoveEmptyꞌ) 0 17 1
B utils.js ➔ ... ➔ describe(ꞌtoJSONꞌ) 0 26 1
A utils.js ➔ ... ➔ it(ꞌpickꞌ) 0 14 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var assert = require('chai').assert,
2
    GedcomX = require('../');
3
4
describe('utils', function(){
5
  
6
  it('removeEmpty', function(){
7
    assert.deepEqual(
8
      GedcomX.utils.removeEmpty({
9
        a: undefined,
10
        b: 0,
11
        c: false,
12
        d: null,
13
        e: ''
14
      }),
15
      {
16
        b: 0,
17
        c: false,
18
        d: null,
19
        e: ''
20
      }
21
    );
22
  });
23
  
24
  it('pick', function(){
25
    assert.deepEqual(
26
      GedcomX.utils.pick({
27
        a: '1',
28
        b: 2,
29
        c: undefined,
30
        d: null
31
      }, ['a','c']),
32
      {
33
        a: '1',
34
        c: undefined
35
      }
36
    );
37
  });
38
  
39
  describe('merge', function(){
40
    
41
    it('objects', function(){
42
      var dest = {},
43
          merged = GedcomX.utils.merge(
44
            dest,
45
            {
46
              a: 1,
47
              b: {
48
                b1: 'foo'
49
              }
50
            },
51
            {
52
              a: 2,
53
              b: {
54
                b2: 'bar'
55
              }
56
            }
57
          );
58
      assert.strictEqual(dest, merged);
59
      assert.deepEqual(
60
        dest,
61
        {
62
          a: 2,
63
          b: {
64
            b1: 'foo',
65
            b2: 'bar'
66
          }
67
        }
68
      );
69
    });
70
    
71
    it('arrays', function(){
72
      var dest = {},
73
          merged = GedcomX.utils.merge(
74
            dest,
75
            {
76
              facts: [
77
                {
78
                  date: {
79
                    formal: '+2001'
80
                  }
81
                }  
82
              ]
83
            }
84
          );
85
      assert.strictEqual(dest, merged);
86
      assert.deepEqual(dest, {
87
        facts: [
88
          {
89
            date: {
90
              formal: '+2001'
91
            }
92
          }  
93
        ]
94
      });
95
    });
96
    
97
  });
98
  
99
  describe('toJSON', function(){
100
    
101
    it('arrays', function(){
102
      assert.deepEqual(
103
        GedcomX.utils.toJSON({
104
          facts: [
105
            GedcomX.Fact({
106
              date: {
107
                formal: '+2001'
108
              }
109
            })
110
          ]
111
        }),
112
        {
113
          facts: [
114
            {
115
              date: {
116
                formal: '+2001'
117
              }
118
            }  
119
          ]
120
        }
121
      );
122
    });
123
    
124
  });
125
  
126
});